package android.homeaccount;

import android.app.Activity;
import android.content.Intent;
import android.homeaccount.R;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;

public class Menu extends Activity
{
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);
        
        TextView tvUsername = (TextView) findViewById(R.id.tvUsername);
        ImageButton ibIncome = (ImageButton) findViewById(R.id.ibIncome);
        ImageButton ibExpend = (ImageButton) findViewById(R.id.ibExpend);
        ImageButton ibSaving = (ImageButton) findViewById(R.id.ibSaving);
        ImageButton ibLogout = (ImageButton) findViewById(R.id.ibLogout);
        
        Intent inboundIntent = getIntent();
        final String login_username = inboundIntent.getExtras().getString("USERNAME");
        tvUsername.setText(tvUsername.getText() + " " + login_username);
        
        ibIncome.setOnClickListener(new OnClickListener()
        {
			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
				Intent intentIncome = new Intent(Menu.this, Income2.class);
				Bundle bundle = new Bundle();
                bundle.putString("USERNAME", login_username);
                intentIncome.putExtras(bundle);
				startActivityForResult(intentIncome, 0);
			}
        });
        ibExpend.setOnClickListener(new OnClickListener()
        {
			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
				Intent intentExpend = new Intent(Menu.this, Expend2.class);
				Bundle bundle = new Bundle();
                bundle.putString("USERNAME", login_username);
                intentExpend.putExtras(bundle);
                startActivityForResult(intentExpend, 0);
			}
        });
        ibSaving.setOnClickListener(new OnClickListener()
        {
			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
				Intent intentSaving = new Intent(Menu.this, Saving.class);
				Bundle bundle = new Bundle();
                bundle.putString("USERNAME", login_username);
                intentSaving.putExtras(bundle);
                startActivityForResult(intentSaving, 0);
			}
        });
        ibLogout.setOnClickListener(new OnClickListener()
        {
			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
				Intent backIntent = Menu.this.getIntent();
				setResult(Login.RESULT_Back, backIntent);
				finish();
			}
        });
    }
    
    protected void onActivityResult(int requestCode, int resultCode, Intent intent)
    {
		super.onActivityResult(requestCode, resultCode, intent);
		if(resultCode == Login.RESULT_Back)
		{	
			int a = Login.RESULT_Back;
		}
	}
}